package com.msw.java;

import java.sql.*;

/**
 * @Author: suncf
 * @Data: 2023年08月15日 17:10
 * @Version: V1.0
 * @Description:TODO
 */
public class PostgreSQLUtils {
    static {
        try {
            Class.forName("org.postgresql.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static Connection getConnnection(String url, String user, String password){
        try {
            return DriverManager.getConnection(url, user, password);
        } catch (SQLException e) {
            System.out.println("Access denied for user (using password: NO)");
            return null;
        }
    }

    public static ResultSet getResultSet(Connection conn , String sql){
        try {
            Statement stat = conn.createStatement();
            return stat.executeQuery(sql);
        } catch (SQLException e) {
            e.printStackTrace();
            return null;
        }
    }
}
